﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using CH.Study.ConsoleApp.ExpressionTree;
using System.Data;

namespace CH.Study.ConsoleApp.ExpressionTree
{
    public abstract class QueryExpressionProvider : IQueryProvider, IQueryExpressionProvider
    {

        public virtual IQueryable<TElement> CreateQuery<TElement>(Expression expression)
        {
            return new QueryQueryable<TElement>(this, expression);
        }

        public virtual IQueryable CreateQuery(Expression expression)
        {
            try
            {

                return (IQueryable)Activator.CreateInstance(
                    typeof(QueryQueryable<>).MakeGenericType(QueryExpressionHelper.GetElementType(expression.Type)),
                    new object[] { this, expression });
            }
            catch
            {
                throw new Exception();
            }
        }

        public abstract TResult Execute<TResult>(Expression expression);
        public abstract object Execute(Expression expression);
        public abstract QueryExpressionDebug GetQueryExpressionDebugMsg(Expression expression);
    }
}
